package me.passtime.projt.fee;

import me.passtime.projt.http.AbstractHttpController;
import me.passtime.projt.http.UriConstants;
import me.passtime.projt.util.PostXmlBuilder;
import me.passtime.projt.util.RequestCode;
import me.passtime.projt.util.ResponseCode;
import me.passtime.projt.util.ToastUtils;

/**
 * Created by IntelliJ IDEA.
 * User: Lee
 * Date: 11-12-16
 * Time: 下午4:37
 */
public class PaymentQueryController extends AbstractHttpController<String> {
    private PaymentSuccessPage successPage;
    public PaymentQueryController(PaymentSuccessPage successPage){
        super(String.class);
        this.successPage = successPage;
    }

    public void queryPayment(String phoneNumber){
        String postXml=new PostXmlBuilder().setSvcCont(RequestCode.QUERY_AVAILABLE_BALANCE).setTelNo(phoneNumber).createXml();
        this.sendRequest(UriConstants.URL,postXml);
    }


    @Override
    public void onRequestFinish(String response) {
        successPage.hideProgressDialog();
        if(ResponseCode.SUCCESS.equals(response)){
            successPage.updateAmount("123.0元");
        }
    }

    @Override
    public void onNetworkAbort() {
        successPage.hideProgressDialog();
        ToastUtils.showMessage(successPage, "错误，网络连接被中断.");
    }

    @Override
    public void onNetworkError() {
        successPage.hideProgressDialog();
        ToastUtils.showMessage(successPage, "错误，网络连接错误.");
    }

    @Override
    public void onResponseError() {
        successPage.hideProgressDialog();
        ToastUtils.showMessage(successPage, "错误，返回结果错误.");
    }
}
